#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>

void openTest(char *file){
    int n,ret,fd;
    char buf[4096];

    fd = open(file, O_RDONLY);
    if(fd == -1){
        // void send_error(int cfd, int status, char *title, char *text);
        perror("send_file:open error");
        close(fd);
        return;
    }
    
    while( (n = read(fd, buf, sizeof(buf))) > 0 ){
        if(n == -1){
            perror("send_file:read error");
            break;
        }

        ret = write(STDOUT_FILENO, buf, n);
        if(ret == -1){
            fprintf(stderr, "errno=%d\n", errno);
            if(errno == EAGAIN) continue;
            else if(errno == EINTR) continue;
            else{
                perror("send_file:send error");
                break;
            }      
        }
    }
    close(fd);
}

int main(){
    openTest("/home/mrzhi/Desktop/dir/client.c");
    return 0;
}